const Koa = require('koa')
const Router = require('koa-router')

const app = new Koa()

let router = new Router()


router.get('/', async (ctx) => {
  ctx.body = '首页'
})

router.get('/news', async (ctx) => {
  ctx.body = '新闻列表页'
})

//获取get传值
/*router.get('/newscontent', async (ctx) => {
  console.log(ctx.method)
  console.log(ctx.query)
  console.log(ctx.querystring)
  ctx.body = '新闻详情页'
})*/
//动态路由
/*router.get('/newscontent/:aid', async (ctx) => {
  console.log(ctx.params)
  ctx.body = ctx.params.aid
})*/

router.get('/newscontent/:aid/:cid', async (ctx) => {
  console.log(ctx.params)
  ctx.body = {
    aid: ctx.params.aid,
    cid: ctx.params.cid
  }
})


app.use(router.routes())
app.use(router.allowedMethods())

app.listen(3000, () => {
  console.log('服务启动成功')
})